package cn.zhpdmmz.service.impl;

import cn.zhpdmmz.entity.Finance;
import cn.zhpdmmz.entity.HotelRoomType;
import cn.zhpdmmz.mapper.FinanceMapper;
import cn.zhpdmmz.service.IFinanceService;
import cn.zhpdmmz.vo.BarVo;
import cn.zhpdmmz.vo.DashboardVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * (Finance)表服务实现类
 *
 * @author ZHP
 * @since 2022-05-21 23:02:21
 */
@Service("financeService")
public class FinanceServiceImpl implements IFinanceService {
    @Resource
    private FinanceMapper financeMapper;


    /**
     * 通过ID查询单条数据
     *
     * @param financeId 主键
     * @return 实例对象
     */
    @Override
    public Finance queryById(Integer financeId) {
        return this.financeMapper.queryById(financeId);
    }

    /**
     * 查询指定行
     *
     * @param finance 筛选条件
     * @return 查询结果
     */
    @Override
    public List<Finance> queryAll(Finance finance) {
        return this.financeMapper.queryAll(finance);
    }

    /**
     * 新增数据
     *
     * @param finance 实例对象
     * @return 实例对象
     */
    @Override
    public Finance insert(Finance finance) {
        this.financeMapper.insert(finance);
        return finance;
    }

    /**
     * 修改数据
     *
     * @param finance 实例对象
     * @return 实例对象
     */
    @Override
    public Finance update(Finance finance) {
        this.financeMapper.update(finance);
        return this.queryById(finance.getFinanceId());
    }

    /**
     * 通过主键删除数据
     *
     * @param financeId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer financeId) {
        return this.financeMapper.deleteById(financeId) > 0;
    }

    @Override
    public List countFinance(){
        List barVoList =new ArrayList();
        List<String> names = new ArrayList<>();
        List<Double> values = new ArrayList<>();
        List <Finance>financeList = this.financeMapper.queryAll(new Finance());
        for(Finance finance : financeList ){
                names.add(finance.getMonth());
                values.add(finance.getSaleAmount());
        }
        barVoList.add(names);
        barVoList.add(values);
        return values;
    }
}
